﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;
using System.Collections.Generic;

public partial class master_ShowPage : System.Web.UI.MasterPage
{
    public string type;
    public string title;
    public string content;
    public string[] pictures;
    public bool hasRelatedPdf;
    public bool hasNotEdit;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["type"] == null)
        {
            Response.Redirect("login.aspx");
            return;
        }
    }

    public void LoadPageData(string pageType)
    {
        type = pageType;
        PageBT pbt = new PageBT();
        title = pbt.GetTitle(type);
        content = pbt.GetContent(type);
        //整合图片路径
        pictures = pbt.GetPictures(type);
        pictures = pbt.ChangePicture(pictures);
        //引用文章
        string[] pdfIds = pbt.GetFiles(type);
        int len = pdfIds.Length;
        if (len == 0)
        {
            hasRelatedPdf = false;
        }
        else
        {
            hasRelatedPdf = true;
            DataTable table = new DataTable();
            table.Columns.Add("id");
            table.Columns.Add("name_cn");
            table.Columns.Add("image_url");
            for (int i = 0; i < len; i++)
            {
                GetPdf gp = new GetPdf();
                DataRow row0 = gp.GetPdfById(int.Parse(pdfIds[i]));
                DataRow row1 = table.NewRow();
                row1["id"] = row0["id"].ToString();
                row1["name_cn"] = row0["name_cn"].ToString();
                row1["image_url"] = row0["image_url"].ToString();
                table.Rows.Add(row1);
            }
            this.Repeater1.DataSource = table;
            this.Repeater1.DataBind();
        }
        if (string.IsNullOrEmpty(title.Trim()) && string.IsNullOrEmpty(content.Trim()) && pictures.Length == 0)
        {
            hasNotEdit = true;
        }
        else
        {
            hasNotEdit = false;
        }
    }
}
